package org.pet.controller;

import org.pet.util.ALiOssUtil;
import org.pet.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {

        String originalFilename = file.getOriginalFilename();
        //使得文件名不重复
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        String url = ALiOssUtil.uploadFile(filename,file.getInputStream());
        System.out.println(url);
        return Result.success(url);
    }
}
